#include <iostream>
#include <vector>

using namespace std;

/**
  * @方法: 官方方法，滑动窗口，剩余的牌点数最小
  * @时间复杂度: o()
  * @空间复杂度: o()
  * @评价: 思路奇特！！！
*/
int maxScore(vector<int>& cardPoints, int k) {
    int t = cardPoints.size() - k;

    int sum = 0;
    for(int i=0;i<t;i++){
        sum += cardPoints[i];
    }

    int minSum = sum;

    for(int i=t;i<cardPoints.size();i++){
        sum += cardPoints[i] - cardPoints[i-t];
        minSum = min(minSum, sum);
    }

    int cnt = 0;
    for(int point : cardPoints){
        cnt += point;
    }
    return cnt - minSum;
}

/**
  * @方法: 递归超时啦！！！！
  * @时间复杂度: o()
  * @空间复杂度: o()
  * @评价:
*/
int recursion1(vector<int>& cardPoints, int k, int left, int right) {
    if(k == 1){
        return max(cardPoints[left], cardPoints[right]);
    }

    return max(cardPoints[left] + recursion1(cardPoints, k - 1, left + 1, right),
               cardPoints[right] + recursion1(cardPoints, k - 1, left, right - 1));
}
int maxScore1(vector<int>& cardPoints, int k) {
    return recursion1(cardPoints, k, 0, cardPoints.size() - 1);
}

int main() {
    cout << "hello world" << endl;
    vector<int> cardPoints{1, 2, 3, 4, 5, 6, 1};
    int ans = maxScore1(cardPoints, 3);
    cout << ans << endl;
}